package com.ymttest.database.mapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ymttest.database.model.MCmbaggrement;
import com.ymttest.database.model.MPayment;
import com.ymttest.database.model.MRefund;

public interface PayGateWayMapper {
	//refundreq
	@Select("select * from refund where Orderid=#{orderid} order by refundid")
	List<MRefund> selectRefundRequestByOrderid(HashMap m);
	@Select("select * from refund where paymentid=#{paymentid}")
    List<MRefund> selectRefundRequestByPaymentid(HashMap m);
	@Select("select * from refund where TradingId=#{tradeNo}")
    List<MRefund> selectRefundRequestByTradeNo(HashMap m);
	
	@Select("select * from refund where RefundId=#{rid}")
	List<MRefund> selectRefundRequestByRefundId(Map m);
	/**
	 * 查询退款
	 * @param m
	 * @return
	 */
	@Select("select * from refund where RefundBatchNo=#{rno}")
	List<MRefund> selectRefundRequestByRefundBatchNo(HashMap m);
    //pppayment
	  /**
     * 查询支付单
     * 
     * @param paymentId
     * @return
     * @throws InterruptedException
     */
	@Select("select * from payment where paymentid=#{paymentId}")
    public List<MPayment> selectPPPaymentByPaymentId(HashMap m);
	
	@Select("select * from payment where tradingid=#{tradingid}")
    public List<MPayment> selectPaymentByTradingid(HashMap m);
	
	@Select("select * from cmbaggrement where userid=#{uid} order by createtime desc")
	MCmbaggrement selectCmbAggrementByUId(Map m);
	
	/**
	 * 查询退款信息 
	 * @param m {pid=PaymentId}
	 * @return
	 */
	@Select("select * from refund where PaymentId=#{pid}")
	List<MRefund> selectRefundRequestByPaymentId(Map m);
	
	
	/**
	 * 更新退款状态
	 * m.put("refundno", refundno);
        m.put("status", status);
	 * @param m
	 * @return
	 */
	@Update("update refund set RefundStatus=#{status} where RefundBatchNo=#{refundno}")
	int updateRefundStatus(Map m);
	
	
	/**
	 * 更新NotifyStatus状态
	 * @param m	 
	   m.put("pid", pid);
        m.put("status", status);
	 * @return
	 */
	@Update("update payment set NotifyStatus=#{status} where paymentid=#{pid}")
	int updateNotifyStatus(Map m);
	@Update("update payment set PayStatus=#{status} where paymentid=#{pid}")
	int updatePayStatus(Map m);
	
	
	/**
	 * 查询退款信息 
	 * @param m {tid=traceid}
	 * @return
	 */
	@Select("select * from refund where RequestId=#{tid}")
	List<MRefund> selectRefundRequestByTraceId(Map m);
	//
//	@Select("select top 10 * from pp_payment where BussinessOrderId=#{bussinessOrderId}")
//	List<MPayment> selectPPPaymentByBussinessOrderId(Map m);

	@Delete("delete from cmbaggrement where userid=#{uid}")
	int deleteCmbAggrementByUId(Map m);
	
	/**
	 * 更新退款审核是否通过
	 * @param m
	 * @return
	 */
	@Update("update refund set IsCancel=#{status} where RefundBatchNo=#{refundno}")
	int updateRefundSoftDeleteFlag(Map m);
	
	//修改审核状态 0 未审核 1 审核 9 自动审核(快速退款)
	@Update("update refund set ApproveStatus=#{status} where RefundBatchNo=#{refundno}")
	int updateRefundApproveStatus(Map m);
		
	/**
	 * 更新RefundRequest 的RefundNo
	 * @param m
	 * @return
	 */
	@Update("update refund set RefundBatchNo= #{rno} where PaymentId=#{pid}")
	int updateRefundNo(Map m);
	@Select("select  * from refund where ApproveStatus=#{approveStatus} order by createtime desc limit 20")
    List<HashMap> queryRefundrequestByApproveStatus(Integer approveStatus);
	@Select("select  * from refund where ApproveStatus=#{approveStatus} and RefundStatus=#{refundStatus} order by createtime desc limit 20")
    List<HashMap> queryRefundrequestByApproveStatusAndRefundStatus(Map m);

	List<MPayment> selectPPBussinessorderByTraceId(Map m);
	
	List<MPayment> selectPPBussinessorderByOrderId(Map m);
	/**
	 * 查询7天之前的没有对账过（CheckStatus） PayPrice 和 trading amount 一致 的数据的 PaymentId
	 * 
	 * @param m
	 *            {paytype=？,paystats=?}
	 * @return PaymentId
	 */
	String selectNoCheckPPaymentId(Map m);
	
	
//	List<RefundRequest> selectRefundRequestByPId(Map m);
	
	/**
	 * 查询发货信息 
	 * @param m {pid=PaymentId}
	 * @return
	 */
	Map selectCompensateProcessInfoByPaymentId(Map m);
	
	/**查询accounting信息
	 * @param m {bid=RefundBatchNo}
	 * @return
	 */
	Map selectPPAccoutingLogByBizno(Map m);
	/**
	 * 查询mock记录
	 * @param m {mockid=mockid}
	 * @return
	 */
	Map selectMockHttpRecordByMockId(Map m);
	
	
	
	
	
	
	
	
	
	
	
	@Select("select * from PP_Payment where BussinessOrderId in(select BussinessOrderId from PP_BussinessOrder where orderid=#{tradid})")
	List<MPayment> selectPPPaymentByTradingId(@Param("tradid")String tradid);
	
}